require('Particles')
HC = require 'hardoncollider'
text = ""
MyCollider = {}

	
function MyCollider.load(world)

	Collider = HC(100, on_collision, collision_stop)
	
	worldColl = world
	playerColl = nil
	parasiteAttracterColl = nil
	glowColl = nil
	blackHoleColl = nil
	parasiteCollArray = {}
	collectbileCollArray = {}
	objectCollArray = {}
	removedCollectibleList = {}
	
end

function MyCollider.addPlayerCollider(x,y,radius)

	playerColl = Collider:addCircle( x, y, radius)
	playerColl.type = "player"
	addparasiteAttracterCollider( x, y)
end

function addparasiteAttracterCollider(x,y)

	parasiteAttracterColl = Collider:addCircle( x, y, 600)
	parasiteAttracterColl.type = "parasiteAttracter"
	
end

function MyCollider.addGlowCollider(x,y,radius)

	glowColl = Collider:addCircle( x, y, radius)
	glowColl.type = "glow"
	
end
function MyCollider.addBlackHoleCollider(x,y,radius)

	blackHoleColl = Collider:addCircle( x, y, radius)
	blackHoleColl.type = "blackhole"
	
end
function MyCollider.addCollectibleCollider(x,y,index)

	--the main list that holds the collectibles needs to match the collectibleCollArray
	--each index needs to be the same
	collectbileCollArray[index] = Collider:addCircle( x, y, 25)
	collectbileCollArray[index].type = "collectible"
	collectbileCollArray[index].location = index
	
end

function MyCollider.addParasiteCollider(x,y,index)

	--the main list that holds the collectibles needs to match the collectibleCollArray
	--each index needs to be the same
	parasiteCollArray[index] = Collider:addCircle( x, y, 25)
	parasiteCollArray[index].type = "parasite"
	parasiteCollArray[index].location = index
	
end

function MyCollider.addObjectCollider(x,y,index,radius)

	--the main list that holds the objects needs to match the collectibleCollArray
	--each index needs to be the same
	objectCollArray[index] = Collider:addCircle( x, y, radius)
	objectCollArray[index].type = "object"
		
end

function MyCollider.update(dt)

	--leaving this code in as a starting point when we need to move everything
	playerColl:moveTo(worldColl.player.x,worldColl.player.y)
	parasiteAttracterColl:moveTo(worldColl.player.x,worldColl.player.y)
	glowColl:moveTo(worldColl.glow.x, worldColl.glow.y)
	
	for i, collider in ipairs(worldColl.collectibleList) do
			
			collectbileCollArray[i]:moveTo(collider.x,collider.y)
			
	end
	for i, parasite in ipairs(worldColl.parasiteList) do
				
			parasiteCollArray[i]:moveTo(parasite.x,parasite.y)
				
	end
	
	Collider:update(dt)
	
end
function MyCollider.getCollectibleCollCount()
	return #collectbileCollArray
end
function MyCollider.draw()
	--leaving this in as a starting point
	--playerColl:draw('line',16)
	--blackHoleColl:draw('line',16)
	--parasiteAttracterColl:draw('line',16)
	--parasiteCollArray[1]:draw('line',16)
end

function MyCollider.setParasiteToGhost(index)
	Collider:setGhost(parasiteCollArray[index])
end
function MyCollider.getCollectibleCollLoc(i)
	return collectbileCollArray[i].location
	       
end
function on_collision(dt, shape_a, shape_b, mtv_x, mtv_y)

	--is this location somthing built into collider or did we add it?
	--aLoc = shape_a.location
	
	if (shape_a.type == "player") and (shape_b.type == "glow") then
		worldColl:playerCollidedWithGlow()
	end
	if (shape_a.type == "player") and (shape_b.type == "collectible") then
				worldColl:playerCollidedWithCollectible(shape_b.location)
				Collider:setGhost(shape_b)
			
			
	end
	if (shape_a.type == "parasiteAttracter") and (shape_b.type == "parasite") then
		worldColl:playerCollidedWithParasite(shape_b.location)
	end
	if (shape_a.type == "player") and (shape_b.type == "blackhole") then
		worldColl:playerCollidedWithBlackHole(shape_b.location)
	end
end

function collision_stop(dt, shape_a, shape_b, mtv_x, mtv_y)
	
end
